<style lang="scss" scoped>

</style>

<template>
    <div class="infobody">
        <dealer-topbar :title="title" @changeStatus="changeStatus" @delItem="delItem" @saveItem="saveItem"></dealer-topbar>
        <div class="content">
            <p class="form-title">医院信息</p>
            <div class="info">
                <Form :model="hospitalInfo" >
                     <!-- <FormItem  label="经销商" >
                        <el-select v-model="hospitalInfo.agentId" clearable placeholder="请选择">
                          <el-option v-for="item in agentList" :key="item.id" :label="item.agentName" :value="item.id"> </el-option>
                        </el-select>
                    </FormItem> -->
                    <FormItem  label="医院名称" >
                        <Input :disabled="status"  v-model="hospitalInfo.hospitalName" placeholder="请输入医院名称" />
                    </FormItem>
                    <FormItem  label="医院地址" >
                        <Input :disabled="status"  v-model="hospitalInfo.hospitalAddr" placeholder="请输入医院地址" />
                    </FormItem>
                    <FormItem  label="联系人" >
                        <Input :disabled="status"  v-model="hospitalInfo.hospitalLinker" placeholder="请输入联系人" />
                    </FormItem>
                    <FormItem  label="联系人电话" >
                        <Input :disabled="status"  v-model="hospitalInfo.hospitalPhone" placeholder="请输入联系人电话" />
                    </FormItem>                    
                </Form>
            </div>
        </div>
    </div>    
</template>

<script>
import dealerTopbar from "@/views/component/dealerTopbar.vue";
import { sampleData } from "api/index.js";
import { error } from 'util';
export default {
  data() {
    return {
      title: "医院",
      status: true,   
      hospitalInfo: {
        hospitalId:"",
        agentId:"",
        hospitalName: "",
        hospitalPhone:"",
        hospitalAddr: "",
        hospitalLinker:""
      }
    };
  },
  methods: {
    changeStatus(param) {
      this.status = param.btnEdit;      
    },
    saveItem(){
      if (this.$store.state.agentOperation == "edit") {
        //调更新接口
         let obj=this.hospitalInfo;
        sampleData.hospitalUpdate(obj).then(res=>{
          if(res.code==0||res.code==200){
            this.$Message.success("修改成功")
            this.$router.push('/hospitalList')
          }else{
            this.$Message.error(res.msg)
          }
        }).catch(error=>{
          this.$Message.error(error)
        })
      } else {
        //调新增接口
        // this.hospitalInfo.agentId=this.$route.query.agentId;
        this.hospitalInfo.agentId=this.$store.state.agentId;
        let obj=this.hospitalInfo;
        sampleData.hospitalAdd(obj).then(res=>{
          if(res.code==0||res.code==200){
            this.$Message.success("添加成功")
            this.$router.push('/hospitalList')
          }else{
            this.$Message.error(res.msg)
          }
        }).catch(error=>{
          this.$Message.error(error)
        })
      }
    },
    delItem(){
      let obj={
        hospitalId:this.$route.query.hospitalId
        }
      sampleData.hospitalDelete(obj).then(res=>{
        if(res.code==0||res.code==200){
          this.$Message.success("删除成功");
          this.$router.push('/hospitalList')
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(error=>{
        this.$Message.error(error)
      })
    },
    getHospitalById(){
      let obj={
        hospitalId:this.$route.query.hospitalId
      }
       sampleData.getHospitalById(obj).then(res=>{
        if(res.code==0||res.code==200){
          this.hospitalInfo=res.hospital;
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(error=>{
        this.$Message.error(error);
      })
    }        
  },
  mounted() {
    if (this.$store.state.agentOperation == "edit") {
      this.status = true;
      this.getHospitalById();
    } else {
      this.status = false;
    }
    console.log(this.$route)
  },
  components: {
    dealerTopbar
  }
};
</script>